package cn.hsp.demo

import java.util.*
import kotlin.math.abs

/**
 * 厦门大学计算机专业 | 前华为工程师
 * 专注《零基础学编程系列》https://cxyxy.blog.csdn.net/article/details/121134634
 * 包含：Java | 安卓 | 前端 | Flutter | iOS | 小程序 | 鸿蒙
 * 公众号：蓝不蓝编程
 */
class BallNumUtil {
    private val random = Random()
    private val RED_BALL_MAX_NUM = 33
    private val BLUE_BALL_MAX_NUM = 16
    val redBallNum: String
        get() {
            val num = getRandom(RED_BALL_MAX_NUM)
            return formatNum(num)
        }
    val blueBallNum: String
        get() {
            val num = getRandom(BLUE_BALL_MAX_NUM)
            return formatNum(num)
        }

    private fun formatNum(num: Int): String {
        return if (num < 10) {
            "0$num"
        } else {
            "" + num
        }
    }

    private fun getRandom(maxValue: Int): Int {
        val randomValue = abs(random.nextInt())
        return randomValue % maxValue + 1
    }
}